<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');  
class Asset {

    private $CI;

    function Asset(){
        $this->CI = & get_instance();
    } 

    private $siteassets = array(
        'type.css' => 'css',
        'styles.css' => 'css',
        'jquery-1.6.2.min.js' => 'js'
    );

    private $endassets = array(
        'core.js' => 'js'
    );

    private $home = array(
        'assets' => array(
            'script_SylvainPapet.js' => 'js',    
            'swfobject.js' => 'js',    
        )
    );
    
    private $onama = array(
        'assets' => array(
            'jquery.jscrollpane.css' => 'css',
            'jquery.jscrollpane.min.js' => 'js',
            'jquery.mousewheel.js' => 'js'   
        )
    );

    private $galerija = array(
        'assets' => array(
            'jd.gallery.css' => 'css',
            'mootools.namespaced.js' => 'js',
            'jd.photo.gallery.namespaced.js' => 'js'    
        )
    
    );
    
    private $sitemap = array(
        'assets' => array(
            'slickmap.css' => 'css',
            'jquery.jscrollpane.css' => 'css',
            'jquery.jscrollpane.min.js' => 'js',
            'jquery.mousewheel.js' => 'js'   
        )
    
    );

    private $usluge = array( 
        'luckaagentura' => array(  
            'teretnibrodovi' => array( 
                'assets' => array (       
                )
            ),
            'brodovinapopravci' => array(
                'assets' => array (            
                )
            ),
            'putnickibrodovi' => array(
                'assets' => array (            
                )
            ),
            'vojnibrodovi' => array(
                'assets' => array (            
                )
            ),
            'imobrodovi' => array(
                'assets' => array (            
                )
            ),
            'istrazivackibrodovi' => array(
                'assets' => array (            
                )
            ),
            'assets' => array (
            )
        ),
        'spedicija' => array(
            'assets' => array (
            )
        ),
        'kontejnerskioperating' => array(
            'assets' => array (
            )
        ),
        'chartering' => array(
            'assets' => array (            
            )           
        ),
        'p_i_zastupnistvo' => array(
            'assets' => array (            
            )
        ),
        'yachting' => array(
            'portomontenegro' => array(
                'assets' => array (            
                )
            ),
            'kotor' => array(
                'assets' => array (            
                )
            ),
            'budva' => array(
                'assets' => array (            
                )
            ),
            'bar' => array(
                'assets' => array (            
                )
            ),
            'lowonyacht' => array(
                'assets' => array (            
                )
            ),
            'contactinfo' => array(
                'assets' => array (            
                )
            ),
            'assets' => array (            
            )
        ),
        'assets' => array (
        'drop_down.js' => 'js',    
        'jquery.jscrollpane.css' => 'css',
        'jquery.jscrollpane.min.js' => 'js',
        'jquery.mousewheel.js' => 'js'    
        )

    );

    private $pageflag = '';  //   OPTIONS -> { page, sub, upsub }

    /*private $home_cms = array(
    'text/edit.js' => 'js',
    'tinymce/tiny_mce.js' => 'js'
    );*/

    function initialze_assets($page, $sub, $upsub){

        /*
        * initialze assets that load for every page
        * site assets loads first
        */ 
        foreach($this->siteassets as $key=>$value){ 
            $this->putAsset($key, $value); 
        }

        /*
        * initialze page assets
        * page assets loads afther site assets
        */
        $this->getPageAssets($page, $sub, $upsub);


        /*
        * initialze assets that load for every page
        * at the end afther site and page assets
        */
        foreach($this->endassets as $key=>$value){    
            $this->putAsset($key, $value); 
        }

    }

    function flag($fl){

        $this->pageflag = $fl;

    }

    function getPageAssets($page, $sub, $upsub){

        /*
        * if array not exisit exit
        */

        if(!isset($this->{$page})) return;

        /*
        * check if page assets exist
        * put assets in montenegrin to load
        */

        if(isset($this->{$page}['assets'])){

            foreach($this->{$page}['assets'] as $key=>$value){
                $this->putAsset($key, $value);
            }

        }

        /*
        * check page flag
        * if not sub or upsub then exit
        */
        if($this->pageflag=='page') return;

        /*
        * check if sub assets exist
        * put assets in montenegrin to load
        */

        if(isset($this->{$page}[$sub]['assets'])){

            foreach($this->{$page}[$sub]['assets'] as $key=>$value){
                $this->putAsset($key, $value);
            }

        }

        /*
        * check page flag
        * if not upsub then exit
        */
        if($this->pageflag=='sub') return;

        if(isset($this->{$page}[$sub][$upsub]['assets'])){

            foreach($this->{$page}[$sub][$upsub]['assets'] as $key=>$value){
                $this->putAsset($key, $value);
            }

        }

        /*
        * check page flag
        * if upsub then exit
        */
        if($this->pageflag=='upsub') return; 

    }

    /*
    * put assets to montenegrin
    * depending on flag
    * css or js
    */ 
    function putAsset($key, $value){

        switch($value){
            case 'css':
                $this->CI->montenegrin->css($key);
                break;
            case 'js':
                $this->CI->montenegrin->js($key);
                break;
        }

    }

}
